#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e4 + 5;

int n, k;
int head[N];
int ver[N << 1], W[N << 1], Next[N << 1], tot;
void add(int u, int v, int w) {
  ++tot;
  ver[tot] = v;
  W[tot] = w;
  Next[tot] = head[u];
  head[u] = tot;
}
ll sum;
int rt, cut[N];
int mx[N], sz[N];
int dis[N], dcnt, tmp[N], tcnt, b[N];
void dfs_c(int u, int fu, int cnt) {
  mx[u] = 0, sz[u] = 1;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu || cut[v]) continue;
    dfs_c(v, u, cnt);
    mx[u] = max(mx[u], sz[v]);
    sz[u] += sz[v];
  }
  mx[u] = max(mx[u], cnt - sz[u]);
  if (!rt || mx[u] < mx[rt]) rt = u;
}
void merge(int a[], int n, int b[], int m, int c[]) {
  int i = 1, j = 1, k = 1;
  while (i <= n && j <= m) {
    if (a[i] <= b[j])
      c[k++] = a[i++];
    else
      c[k++] = b[j++];
  }
  while (i <= n) c[k++] = a[i++];
  while (j <= m) c[k++] = b[j++];
  rep(i, 1, n + m) a[i] = c[i];
}
void dfs_d(int u, int fu, int d) {
  tmp[++tcnt] = d;
  sz[u] = 1;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu || cut[v]) continue;
    int w = W[i];
    dfs_d(v, u, d + W[i]);
    sz[u] += sz[v];
  }
}
void solve(int u, int cnt) {
  // find the center
  rt = 0;
  dfs_c(u, u, cnt);
  u = rt;
  // dis from rt
  dcnt = 0;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (cut[v]) continue;
    tcnt = 0;
    dfs_d(v, u, W[i]);
    for (int j = 1; j <= tcnt; j++) {
      if (tmp[j] > k) continue;
      sum++;
      sum += upper_bound(dis + 1, dis + dcnt + 1, k - tmp[j]) - dis - 1;
    }
    sort(tmp + 1, tmp + tcnt + 1);
    merge(dis, dcnt, tmp, tcnt, b);
    dcnt += tcnt;
  }
  cut[u] = 1;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (cut[v]) continue;
    solve(v, sz[v]);
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  while ((cin >> n >> k) && n && k) {
    // clear edges
    rep(i, 1, n) head[i] = 0, cut[i] = 0;
    tot = 0;
    // read edges
    rep(i, 2, n) {
      int u, v, w;
      cin >> u >> v >> w;
      u++, v++;
      add(u, v, w), add(v, u, w);
    }
    // calc sum
    sum = 0;
    solve(1, n);
    cout << sum << endl;
  }
  return 0;
}